package com.example.springboot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springboot.entity.Story;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface StoryMapper extends BaseMapper<Story> {

    Story selectStoryById(@Param("id") Long id);

    IPage<Story> selectStoriesPage(Page<Story> page);

    IPage<Story> selectHotStories(Page<Story> page);

    @Update("UPDATE story SET views = views + 1 WHERE id = #{id}")
    int incrementViews(@Param("id") Long id);

    // 新增方法
    IPage<Story> selectStoriesByCategory(@Param("category") String category, Page<Story> page);

    IPage<Story> selectStoriesByDestination(@Param("destinationId") Long destinationId, Page<Story> page);

    IPage<Story> selectStoriesByAuthor(@Param("authorId") Long authorId, Page<Story> page);

    IPage<Story> searchStories(@Param("keyword") String keyword, Page<Story> page);

    List<String> selectAllCategories();

    List<Map<String, Object>> selectCategoryStats();

    int selectHotCount();

    int selectRecentCount();

    @Update("UPDATE story SET likes = likes + 1 WHERE id = #{id}")
    int incrementLikes(@Param("id") Long id);
    
    // 重命名方法以避免与XML定义冲突
    List<Story> getRelatedStories(@Param("storyId") Long storyId, @Param("limit") Integer limit);
    
    List<Story> selectLatestStories(@Param("size") Integer size);
}
